package xyz.zdsoft.auth_module.utils;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import xyz.zdsoft.auth_module.vo.CheckUser;
import java.util.concurrent.TimeUnit;

public class UserList {

    private static UserList instance = new UserList();

    private static final ExpiringMap<String, CheckUser> localUser = ExpiringMap.builder()
            .maxSize(200)
            .expiration(30, TimeUnit.MINUTES)
            .expirationPolicy(ExpirationPolicy.ACCESSED)
            .variableExpiration()
            .build();

    private UserList(){

    }

    public static UserList getInstance(){
        return instance;
    }

    public CheckUser addUser(String token,CheckUser checkUser){
        return localUser.put(token,checkUser);
    }

    public CheckUser removeUser(String token){
        return localUser.remove(token);
    }

    public CheckUser getUser(String token){
        return localUser.get(token);
    }

    public ExpiringMap<String, CheckUser> getAllUser(){
        return localUser;
    }

    public int getUserNumber(){
        return localUser.size();
    }


}
